package com.example.springboot.controller;

import com.example.springboot.entity.Song;
import com.example.springboot.service.SongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author heyunlin
 * @version 1.0
 */
@RestController
@RequestMapping(path = "/song", produces="application/json;charset=utf-8")
public class SongController {

    private final SongService songService;

    @Autowired
    public SongController(SongService songService) {
        this.songService = songService;
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public void insert(Song song) {
        songService.insert(song);
    }

    @RequestMapping(value = "/deleteById/{id}", method = RequestMethod.GET)
    public void deleteById(@PathVariable("id") String id) {
        songService.deleteById(id);
    }

    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public void updateById(Song song) {
        songService.updateById(song);
    }

    @RequestMapping(value = "/selectById/{id}", method = RequestMethod.GET)
    public Song selectById(@PathVariable("id") String id) {
        return songService.selectById(id);
    }

}